﻿using System;
using System.IO;
using System.Reflection;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ModLoader.Default.Patreon;

namespace Terraria.ModLoader.Default
{
	// Token: 0x020002FE RID: 766
	internal class ModLoaderMod : Mod
	{
		// Token: 0x170001E7 RID: 487
		// (get) Token: 0x06001D39 RID: 7481 RVA: 0x00014ADC File Offset: 0x00012CDC
		public override string Name
		{
			get
			{
				return "ModLoader";
			}
		}

		// Token: 0x170001E8 RID: 488
		// (get) Token: 0x06001D3A RID: 7482 RVA: 0x00014AE3 File Offset: 0x00012CE3
		public override Version Version
		{
			get
			{
				return ModLoader.version;
			}
		}

		// Token: 0x170001E9 RID: 489
		// (get) Token: 0x06001D3B RID: 7483 RVA: 0x00014AE3 File Offset: 0x00012CE3
		public override Version tModLoaderVersion
		{
			get
			{
				return ModLoader.version;
			}
		}

		// Token: 0x06001D3C RID: 7484 RVA: 0x00014AEA File Offset: 0x00012CEA
		internal ModLoaderMod()
		{
			base.Side = ModSide.NoSync;
			base.DisplayName = "tModLoader";
		}

		// Token: 0x06001D3D RID: 7485 RVA: 0x0043883C File Offset: 0x00436A3C
		public override void Load()
		{
			ModLoaderMod.LoadTextures();
			base.AddTexture("MysteryItem", ModLoaderMod.mysteryItemTexture);
			base.AddTexture("StartBag", ModLoaderMod.startBagTexture);
			base.AddTexture("MysteryTile", ModLoaderMod.mysteryTileTexture);
			base.AddItem("MysteryItem", new MysteryItem());
			base.AddGlobalItem("MysteryGlobalItem", new MysteryGlobalItem());
			base.AddItem("StartBag", new StartBag());
			base.AddItem("AprilFools", new AprilFools());
			base.AddTile("MysteryTile", new MysteryTile(), "ModLoader/MysteryTile");
			base.AddTile("PendingMysteryTile", new MysteryTile(), "ModLoader/MysteryTile");
			base.AddTileEntity("MysteryTileEntity", new MysteryTileEntity());
			base.AddPlayer("MysteryPlayer", new MysteryPlayer());
			base.AddModWorld("MysteryWorld", new MysteryWorld());
			base.AddModWorld("MysteryTilesWorld", new MysteryTilesWorld());
			base.AddCommand("HelpCommand", new HelpCommand());
			base.AddCommand("ModlistCommand", new ModlistCommand());
			this.AddPatreon();
		}

		// Token: 0x06001D3E RID: 7486 RVA: 0x00438950 File Offset: 0x00436B50
		private void AddPatreon()
		{
			this.AddPatreonItemAndEquipType(new toplayz_Head(), "toplayz", EquipType.Head);
			this.AddPatreonItemAndEquipType(new toplayz_Body(), "toplayz", EquipType.Body);
			this.AddPatreonItemAndEquipType(new toplayz_Legs(), "toplayz", EquipType.Legs);
			this.AddPatreonItemAndEquipType(new KittyKitCatCat_Head(), "KittyKitCatCat", EquipType.Head);
			this.AddPatreonItemAndEquipType(new KittyKitCatCat_Body(), "KittyKitCatCat", EquipType.Body);
			this.AddPatreonItemAndEquipType(new KittyKitCatCat_Legs(), "KittyKitCatCat", EquipType.Legs);
			this.AddPatreonItemAndEquipType(new PotyBlank_Head(), "PotyBlank", EquipType.Head);
			this.AddPatreonItemAndEquipType(new PotyBlank_Body(), "PotyBlank", EquipType.Body);
			this.AddPatreonItemAndEquipType(new PotyBlank_Legs(), "PotyBlank", EquipType.Legs);
			this.AddPatreonItemAndEquipType(new Dinidini_Head(), "dinidini", EquipType.Head);
			this.AddPatreonItemAndEquipType(new Dinidini_Body(), "dinidini", EquipType.Body);
			this.AddPatreonItemAndEquipType(new Dinidini_Legs(), "dinidini", EquipType.Legs);
			this.AddPatreonItemAndEquipType(new Dinidini_Wings(), "dinidini", EquipType.Wings);
		}

		// Token: 0x06001D3F RID: 7487 RVA: 0x00438A3C File Offset: 0x00436C3C
		private void AddPatreonItemAndEquipType(ModItem item, string name, EquipType equipType)
		{
			if (!Main.dedServ)
			{
				base.AddTexture(string.Format("Patreon.{0}_{1}", name, equipType), ModLoaderMod.ReadTexture(string.Format("Patreon.{0}_{1}", name, equipType)));
				base.AddTexture(string.Format("Patreon.{0}_{1}_{2}", name, equipType, equipType), ModLoaderMod.ReadTexture(string.Format("Patreon.{0}_{1}_{2}", name, equipType, equipType)));
				if (equipType == EquipType.Body)
				{
					base.AddTexture(string.Format("Patreon.{0}_{1}_Arms", name, equipType), ModLoaderMod.ReadTexture(string.Format("Patreon.{0}_{1}_Arms", name, equipType)));
				}
			}
			base.AddItem(string.Format("{0}_{1}", name, equipType), item);
			base.AddEquipTexture(item, equipType, item.Name, item.Texture + "_" + equipType, item.Texture + "_Arms", item.Texture + "_FemaleBody");
		}

		// Token: 0x06001D40 RID: 7488 RVA: 0x00014B04 File Offset: 0x00012D04
		private static void LoadTextures()
		{
			if (Main.dedServ)
			{
				return;
			}
			ModLoaderMod.mysteryItemTexture = ModLoaderMod.ReadTexture("MysteryItem");
			ModLoaderMod.startBagTexture = ModLoaderMod.ReadTexture("StartBag");
			ModLoaderMod.mysteryTileTexture = ModLoaderMod.ReadTexture("MysteryTile");
			ModLoaderMod.texturesLoaded = true;
		}

		// Token: 0x06001D41 RID: 7489 RVA: 0x00438B48 File Offset: 0x00436D48
		private static Texture2D ReadTexture(string file)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			Stream manifestResourceStream = executingAssembly.GetManifestResourceStream("Terraria.ModLoader.Default." + file + ".png");
			return Texture2D.FromStream(Main.instance.GraphicsDevice, manifestResourceStream);
		}

		// Token: 0x040018E8 RID: 6376
		private static bool texturesLoaded;

		// Token: 0x040018E9 RID: 6377
		private static Texture2D mysteryItemTexture;

		// Token: 0x040018EA RID: 6378
		private static Texture2D startBagTexture;

		// Token: 0x040018EB RID: 6379
		private static Texture2D mysteryTileTexture;
	}
}
